local ImageButton = require "widgets/imagebutton"
local Image = require "widgets/image"
local t_util = require "libs/tableutil"
local Widget = require "widgets/widget"


-- 有value时为不显示

local BoneHelm = Class(Widget, function(self, side, show, value, func)
    Widget._ctor(self, "BoneHelm")
    local btn = self:AddChild(ImageButton("images/quagmire_recipebook.xml", "cookbook_known.tex"))
    self.btn = btn
    btn:ForceImageSize(side, side)
    local btn_size = btn:GetSize()
    local btn_scale = side/btn_size
    btn:SetNormalScale(btn_scale)
    btn:SetFocusScale(btn_scale)
    btn.bg = btn:AddChild(Image(GetInventoryItemAtlas("nightmarefuel.tex"), "nightmarefuel.tex"))
    btn.img_or = btn:AddChild(Image("images/shroomcake_moreicons.xml", "right.tex"))
    btn.img_or:ScaleToSize(side/1.1, side/1.1)
    btn.bg:ScaleToSize(side, side)
    btn:SetOnClick(function()
        self:SetBtnImg(not btn.value)
        func(btn.value)
    end)
    if not show then self:Hide() end
    self:SetBtnImg(value)
end)

function BoneHelm:Hide()
    self:SetBtnImg(false)
    BoneHelm._base.Hide(self)
end

function BoneHelm:Show()
    self:SetBtnImg(false)
    BoneHelm._base.Show(self)
end

function BoneHelm:SetBtnImg(needhide)
    self.btn.value = needhide
    self.btn.img_or:SetTexture("images/shroomcake_moreicons.xml", self.btn.value and "wrong.tex" or "right.tex")
    self.btn:SetHoverText(self.btn.value and "点击显示暗影生物！" or "点击隐藏暗影生物！", {font = NEWFONT_OUTLINE, offset_y = 90})
end


return BoneHelm